import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Jiang Jinxi
 * Date: 2024-04-17
 * Time: 19:19
 */
public enum EnumTest {
    //枚举实例必须放在第一行
    RED("red",1),BLACK("black",2),WHITE("white",3),GREEN("green",4);
    //参数
    private String name;
    private int key;
   //1、当枚举对象有参数后，需要提供相应的构造函数
   //2、枚举的构造函数默认是私有的 这个一定要记住
    //构造方法
    private EnumTest (String name,int key) {
        this.name = name;
        this.key = key;
    }
    //方法
    public static EnumTest getEnumKey (int key) {
        for (EnumTest t: EnumTest.values()) {
            if(t.key == key) {
                return t;
            }
        }
        return null;
    }
    public static void main(String[] args) {
        System.out.println(getEnumKey(2));
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>((o1,o2) -> {
            return o1.compareTo(o2);
        });
        //因为只有一个return语句, 所以return也可以省略
        PriorityQueue<Integer> priorityQueue1 = new PriorityQueue<Integer>((o1, o2) -> o1.compareTo(o2));
    }


    public static void main3(String[] args) {
        EnumTest[] testEnum2 = EnumTest.values();
        for (int i = 0; i < testEnum2.length; i++) {
            System.out.println(testEnum2[i] + " " + testEnum2[i].ordinal());
        }
        System.out.println("=========================");
        System.out.println(EnumTest.valueOf("GREEN"));
        System.out.println("=========================");
//拿到枚举实例BLACK
        EnumTest testEnum1 = EnumTest.BLACK;
//拿到枚举实例RED
        EnumTest testEnum3 = EnumTest.RED;
        System.out.println(testEnum1.compareTo(testEnum3));
        System.out.println(BLACK.compareTo(RED));
        System.out.println(RED.compareTo(BLACK));
    }

    public static void main1(String[] args) {
        EnumTest testEnum2 = EnumTest.BLACK;
        switch (testEnum2) {
            case RED:
                System.out.println("red");
                break;
            case BLACK:
                System.out.println("black");
                break;
            case WHITE:
                System.out.println("WHITE");
                break;
            case GREEN:
                System.out.println("black");
                break;
            default:
                break;
        }
    }
}
